import {guid} from '@/utils';

export function defaultModel() {
  return {
    id: guid(),
    nodes: [
      {id: 'start', type: 'start'},
      {id: 'end', type: 'end'}
    ],
    edges: [
      {source: 'start', target: 'end'}
    ],
    gatewayPairs: [],
    enable: 1,                   //是否启用
    flowModelName: undefined,    // 流程名称
    formType: 'test',         //单据类型
    titleFormula: undefined,     //流程标题公式
    titleFormulaText: undefined, //流程标题公式翻译
    beforeListeners: undefined,  //流程开始之前监听器
    afterListeners: undefined,   //流程结束之后的监听
  };
  // return {"formType":"test","id":"1710597653351814973","titleFormula":"1+1","nodes":[{"id":"start","type":"start"},{"id":"end","type":"end"},{"id":"1711105475769391777","type":"userTask","taskName":"用户任务1","notify":1,"executeWay":"multiCompetition","executeThreshold":100,"actionAuth":"default","manualSelectUser":0,"autoComplete":0,"mustSignature":0},{"id":"1711105482939833564","type":"userTask","taskName":"1","notify":0,"executeWay":"multiCompetition","executeThreshold":100,"actionAuth":"default","manualSelectUser":0,"autoComplete":1,"mustSignature":0,"beforeEnterListeners":"common"},{"id":"1711105497572785214","type":"gateway","executeWay":"exclusive"},{"id":"1711105497572489444","type":"gateway"},{"id":"171110549451796655","type":"userTask","taskName":"5","notify":0,"executeWay":"multi","executeThreshold":100,"actionAuth":"default","manualSelectUser":1,"autoComplete":0,"mustSignature":0},{"id":"171110549908987729","type":"userTask","taskName":"1","notify":0,"executeWay":"multiSequence","executeThreshold":100,"actionAuth":"default","manualSelectUser":0,"autoComplete":1,"mustSignature":0},{"id":"1711105505114486281","type":"empty"},{"id":"1711105505114995795","type":"gateway","executeWay":"include"},{"id":"171110550511447395","type":"gateway","executeWay":"include"},{"id":"1711105512916549293","type":"userTask","taskName":"333","notify":0,"executeWay":"multiCompetition","executeThreshold":100,"actionAuth":"default","manualSelectUser":1,"autoComplete":0,"mustSignature":0},{"id":"1711105517978784748","type":"userTask","taskName":"4","notify":0,"executeWay":"single","executeThreshold":100,"actionAuth":"default","manualSelectUser":1,"autoComplete":0,"mustSignature":0},{"id":"1711930568996429628","type":"userTask","taskName":"5","notify":0,"executeWay":"single","executeThreshold":100,"actionAuth":"default","manualSelectUser":1,"autoComplete":0,"mustSignature":0,"addCountSign":0}],"edges":[{"id":"1711105477915893815","source":"start","target":"1711105475769391777","priority":0},{"id":"1711105485563328535","source":"1711105475769391777","target":"1711105497572785214","priority":0},{"id":"171110549068453719","source":"1711930568996429628","target":"end","priority":0},{"id":"1711105497572937178","source":"1711105497572785214","target":"1711105482939833564","priority":4,"formula":"{age:number:年龄}==10","formulaText":"年龄==10"},{"id":"1711105497572742917","source":"171110550511447395","target":"1711105497572489444","priority":0},{"id":"1711105497572823906","source":"1711105497572785214","target":"171110549451796655","priority":0},{"id":"1711105497572769253","source":"171110549451796655","target":"1711105497572489444","priority":0},{"id":"1711105502100966116","source":"1711105482939833564","target":"1711105505114995795","priority":0},{"id":"1711105505114607444","source":"1711105505114995795","target":"171110549908987729","priority":0},{"id":"171110550511465433","source":"1711105517978784748","target":"171110550511447395","priority":0},{"id":"1711105505114611268","source":"1711105505114995795","target":"1711105505114486281","priority":0},{"id":"1711105505114825739","source":"1711105505114486281","target":"171110550511447395","priority":0},{"id":"1711105515751946832","source":"1711105505114995795","target":"1711105512916549293","priority":0,"formula":"1+1==2","formulaText":"1+1==2"},{"id":"1711105515751726572","source":"1711105512916549293","target":"171110550511447395","priority":0},{"id":"1711105520534325914","source":"171110549908987729","target":"1711105517978784748","priority":0},{"id":"1711930584769727578","source":"1711105497572489444","target":"1711930568996429628","priority":0}],"gatewayPairs":[{"id":"1711105497572173283","source":"1711105497572785214","target":"1711105497572489444"},{"id":"1711105505114151890","source":"1711105505114995795","target":"171110550511447395"}]}
  // return {"formType":"test","id":"1710597653351814973","titleFormula":"1+1","nodes":[{"id":"start","type":"start"},{"id":"end","type":"end"},{"id":"1711105475769391777","type":"userTask","taskName":"用户任务1","notify":1,"executeWay":"multiCompetition","executeThreshold":100,"actionAuth":"default","manualSelectUser":0,"autoComplete":0,"mustSignature":0},{"id":"1711105482939833564","type":"userTask","taskName":"用户任务2","notify":0,"executeWay":"multiCompetition","executeThreshold":100,"actionAuth":"default","manualSelectUser":0,"autoComplete":0,"mustSignature":0,"beforeEnterListeners":"common"},{"id":"1711105497572785214","type":"gateway","executeWay":"exclusive"},{"id":"1711105497572489444","type":"gateway"},{"id":"171110549451796655","type":"userTask","taskName":"用户任务3","notify":0,"executeWay":"multiCompetition","executeThreshold":100,"actionAuth":"default","manualSelectUser":0,"autoComplete":0,"mustSignature":0},{"id":"171110549908987729","type":"userTask","taskName":"用户任务4","notify":0,"executeWay":"multiSequence","executeThreshold":100,"actionAuth":"default","manualSelectUser":0,"autoComplete":0,"mustSignature":0},{"id":"1711105505114486281","type":"empty"},{"id":"1711105505114995795","type":"gateway","executeWay":"include"},{"id":"171110550511447395","type":"gateway","executeWay":"include"},{"id":"1711105512916549293","type":"userTask","taskName":"用户任务5","notify":0,"executeWay":"multiCompetition","executeThreshold":100,"actionAuth":"default","manualSelectUser":0,"autoComplete":0,"mustSignature":0},{"id":"1711105517978784748","type":"userTask","taskName":"用户任务6","notify":0,"executeWay":"multiCompetition","executeThreshold":100,"actionAuth":"default","manualSelectUser":0,"autoComplete":0,"mustSignature":0}],"edges":[{"id":"1711105477915893815","source":"start","target":"1711105475769391777","priority":0},{"id":"1711105485563328535","source":"1711105475769391777","target":"1711105497572785214","priority":0},{"id":"171110549068453719","source":"1711105497572489444","target":"end","priority":0},{"id":"1711105497572937178","source":"1711105497572785214","target":"1711105482939833564","priority":4,"formula":"{age:number:年龄}==10","formulaText":"年龄==10"},{"id":"1711105497572742917","source":"171110550511447395","target":"1711105497572489444","priority":0},{"id":"1711105497572823906","source":"1711105497572785214","target":"171110549451796655","priority":0},{"id":"1711105497572769253","source":"171110549451796655","target":"1711105497572489444","priority":0},{"id":"1711105502100966116","source":"1711105482939833564","target":"1711105505114995795","priority":0},{"id":"1711105505114607444","source":"1711105505114995795","target":"171110549908987729","priority":0},{"id":"171110550511465433","source":"1711105517978784748","target":"171110550511447395","priority":0},{"id":"1711105505114611268","source":"1711105505114995795","target":"1711105505114486281","priority":0},{"id":"1711105505114825739","source":"1711105505114486281","target":"171110550511447395","priority":0},{"id":"1711105515751946832","source":"1711105505114995795","target":"1711105512916549293","priority":0,"formula":"1+1==3","formulaText":"1+1==3"},{"id":"1711105515751726572","source":"1711105512916549293","target":"171110550511447395","priority":0},{"id":"1711105520534325914","source":"171110549908987729","target":"1711105517978784748","priority":0}],"gatewayPairs":[{"id":"1711105497572173283","source":"1711105497572785214","target":"1711105497572489444"},{"id":"1711105505114151890","source":"1711105505114995795","target":"171110550511447395"}]}
}

export function createEmptyUserTask() {
  return {
    id: guid(),
    type: 'userTask',
    taskName: '用户任务',
    taskKey: undefined,
    notify: 0, // 是否知会
    executeWay: 'multiCompetition', //执行方式： single： 单用户， multiCompetition：多人竞争，multiSequence多人依次执行，multi：多人同时审批
    executeThreshold: 100, //结束阈值(百分比, 向下取整加1)
    actionAuth: 'default', //审批按钮权限
    manualSelectUser: 0, //是否支持手动设置审批人
    autoComplete: 0, //是否支持自动通过
    mustSignature: 0, //是否需要强制手签
    addCountSign: 0, //是否来自加签
    addCountSignUsers: undefined, //加签的用户id
    addCountSignUserNames: undefined, //加签的用户名称
    userConfigs: undefined,//用户配置(用来查找用户), 交给第三方定义数据结构

    beforeEnterListeners: undefined, //进入这个节点之前的监听器
    afterEnterListeners: undefined,  //进入这个节点之后的监听器
    beforeComplete: undefined,       //审批这个节点之前的监听器
    afterComplete: undefined,        //审批这个节点之后的监听器
    pcView: undefined, //pc视图
    pcAction: undefined, //pc权限
    mobileView: undefined, //移动端视图
    mobileAction: undefined, //移动端权限

    userTaskType: 'col', //协同节点

    exts: {}, //扩展属性

    remark: undefined, //备注

    passNodeWithdrawAble: true
  };
}

export const startNode = {
  id: 'start',
  beforeEnterListeners: undefined, //进入这个节点之前的监听器
  afterEnterListeners: undefined,  //进入这个节点之后的监听器
};

export const endNode = {
  id: 'end',
  beforeEnterListeners: undefined, //进入这个节点之前的监听器
  afterEnterListeners: undefined,  //进入这个节点之后的监听器
};

export function createEdge(source, target) {
  return {
    id: guid(),
    remark: undefined,
    source, target,
    priority: 0,
    formula: undefined,
    formulaText: undefined,
  };
}

export function createGatewayPair(start, end) {
  return {
    id: guid(),
    source: start.id,
    target: end.id,
  };
}

export function createGateway() {
  return {id: guid(), type: 'gateway', executeWay: 'include'}; //include 多分支网关，exclusive 单分支网关
}

export function createEmptyNode() {
  return {
    id: guid(),
    type: 'empty',
  };
}

export const gatewayExecuteWayOptions = [
  {label: '单分支网关', value: 'exclusive'},
  {label: '多分支网关', value: 'include'},
];
